# 导入turtle模块
import turtle
import math

# 设置画笔
def setup_pen():
    pen = turtle.Turtle()
    pen.speed(5)  # 设置画笔速度
    pen.color('red')  # 设置画笔颜色为红色
    pen.fillcolor('red')  # 设置填充颜色为红色
    pen.pensize(2)  # 设置画笔粗细
    return pen

# 画爱心的函数
def draw_heart():
    pen = setup_pen()
    
    # 抬起画笔，移动到起始位置
    pen.penup()
    pen.goto(0, -100)
    pen.pendown()
    
    # 开始填充
    pen.begin_fill()
    
    # 画左半边爱心
    pen.left(140)
    pen.forward(224)
    
    # 画左上弧
    for _ in range(200):
        pen.right(1)
        pen.forward(2)
    
    # 画右上弧
    pen.left(120)
    for _ in range(200):
        pen.right(1)
        pen.forward(2)
    
    # 画右半边直线
    pen.forward(224)
    
    # 结束填充
    pen.end_fill()
    
    # 写字
    pen.penup()
    pen.goto(0, 50)
    pen.color('white')
    pen.write("Python真有趣!", align="center", font=("Arial", 20, "bold"))
    
    # 隐藏画笔
    pen.hideturtle()

# 设置窗口
def setup_window():
    window = turtle.Screen()
    window.bgcolor('pink')  # 设置背景色为粉色
    window.title('Python绘制爱心')  # 设置窗口标题

def main():
    setup_window()
    draw_heart()
    turtle.done()  # 保持窗口显示

if __name__ == "__main__":
    main() 